module(
    name = "contrib_rules_jvm",
    version = "0.31.1",
    repo_name = "contrib_rules_jvm",
)

PROTOBUF_VERSION = "21.7"

# The java packages are published to maven under a different versioning scheme.
PROTOBUF_JAVA_VERSION = "3.{}".format(PROTOBUF_VERSION)

bazel_dep(name = "apple_rules_lint", version = "0.4.0")
bazel_dep(name = "bazel_skylib", version = "1.8.1")
bazel_dep(name = "gazelle", version = "0.42.0", repo_name = "bazel_gazelle")
bazel_dep(name = "protobuf", version = "29.1", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_cc", version = "0.1.1")
bazel_dep(name = "rules_go", version = "0.52.0")
bazel_dep(name = "rules_java", version = "8.5.1")
bazel_dep(name = "rules_jvm_external", version = "6.7")
bazel_dep(name = "rules_proto", version = "7.0.2")
bazel_dep(name = "bazel_lib", version = "3.0.0")

bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.8.1", dev_dependency = True)
bazel_dep(name = "rules_python", version = "1.5.4", dev_dependency = True)
bazel_dep(name = "rules_shell", version = "0.6.0", dev_dependency = True)
bazel_dep(name = "stardoc", version = "0.7.2", dev_dependency = True, repo_name = "io_bazel_stardoc")

linter = use_extension("@apple_rules_lint//lint:extensions.bzl", "linter")
linter.register(name = "java-checkstyle")
linter.configure(
    name = "java-checkstyle",
    config = "//java:checkstyle-default-config",
)
linter.register(name = "java-pmd")
linter.configure(
    name = "java-pmd",
    config = "//java:pmd-config",
)
linter.register(name = "java-spotbugs")
linter.configure(
    name = "java-spotbugs",
    config = "//java:spotbugs-default-config",
)
use_repo(
    linter,
    "apple_linters",
)

# There is a `grpc_java` bazel_dep we could use, but that pollutes the main
# `maven` namespace and patches `protobuf` too. Instead, we pull the http
# archive and patch it so we can use it in the one target we care about
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "grpc-java",
    integrity = "sha256-KUKla3lEeaC8HA5pA5ya5hXxyznQ468SrzXA6zvXP98=",
    patch_args = ["-p1"],
    patches = [
        "//third_party:grpc-java.patch",
    ],
    strip_prefix = "grpc-java-1.71.0",
    url = "https://github.com/grpc/grpc-java/archive/refs/tags/v1.71.0.tar.gz",
)

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")

IO_GRPC_GRPC_JAVA_ARTIFACTS = [
    "com.google.api.grpc:proto-google-common-protos:2.9.0",
    "com.google.guava:failureaccess:1.0.1",
    "org.apache.tomcat:annotations-api:6.0.53",
    "org.codehaus.mojo:animal-sniffer-annotations:1.21",
]

slf4j_version = "1.7.32"

spotbugs_version = "4.8.6"

maven.install(
    name = "contrib_rules_jvm_deps",
    artifacts = [
        "com.github.spotbugs:spotbugs-annotations:%s" % spotbugs_version,
        "com.google.code.findbugs:jsr305:3.0.2",
        "com.google.errorprone:error_prone_annotations:2.35.1",
        "com.google.googlejavaformat:google-java-format:1.24.0",
        "com.google.guava:guava:33.3.1-jre",
        "commons-cli:commons-cli:1.9.0",
        "io.grpc:grpc-api",
        "io.grpc:grpc-core",
        "io.grpc:grpc-netty",
        "io.grpc:grpc-services",
        "io.grpc:grpc-stub",

        # These can be versioned independently of the versions in `repositories.bzl`
        # so long as the version numbers are higher.
        "org.junit.jupiter:junit-jupiter-engine",
        "org.junit.jupiter:junit-jupiter-api",
        "org.junit.platform:junit-platform-launcher",
        "org.junit.platform:junit-platform-reporting",
        "org.junit.vintage:junit-vintage-engine",

        # Open Test Alliance for the JVM dep
        "org.opentest4j:opentest4j:1.3.0",

        # Checkstyle deps
        "com.puppycrawl.tools:checkstyle:10.20.2",

        # PMD deps
        "net.sourceforge.pmd:pmd-dist:7.8.0",

        # Spotbugs deps
        "org.slf4j:slf4j-api:%s" % slf4j_version,
        "org.slf4j:slf4j-jdk14:%s" % slf4j_version,

        # Used by us at runtime
        "org.slf4j:slf4j-simple:%s" % slf4j_version,

        # For Kotlin parsing in the Gazelle plugin
        "org.jetbrains.kotlin:kotlin-compiler:2.2.20",

        # We explicitly declare a protobuf runtime version
        # so that it coincides with the one we use to generate the code.
        "com.google.protobuf:protobuf-java:{}".format(PROTOBUF_JAVA_VERSION),
    ] + IO_GRPC_GRPC_JAVA_ARTIFACTS,
    boms = [
        "io.grpc:grpc-bom:1.68.2",
        "org.junit:junit-bom:5.11.3",
    ],
    fail_if_repin_required = True,
    lock_file = "//:contrib_rules_jvm_deps_install.json",
    resolver = "maven",
)

# Spotbugs deps
# We don't want to force people to use 1.8-beta
# but we can't use the `maven` macros because
# we've not loaded rules yet. Fortunately, the
# expansion is easy :)
maven.artifact(
    name = "contrib_rules_jvm_deps",
    artifact = "spotbugs",
    exclusions = ["org.slf4j:slf4j-api"],
    group = "com.github.spotbugs",
    version = spotbugs_version,
)
use_repo(maven, "contrib_rules_jvm_deps")

dev_maven = use_extension(
    "@rules_jvm_external//:extensions.bzl",
    "maven",
    dev_dependency = True,
)
dev_maven.install(
    name = "contrib_rules_jvm_tests",
    artifacts = [
        # These can be versioned independently of the versions in `repositories.bzl`
        # so long as the version numbers are higher.
        "org.junit.jupiter:junit-jupiter-engine:5.8.2",
        "org.junit.jupiter:junit-jupiter-api:5.8.2",
        "org.junit.jupiter:junit-jupiter-params:5.8.2",
        "org.junit.platform:junit-platform-launcher:1.8.2",
        "org.junit.platform:junit-platform-reporting:1.8.2",
        "org.junit.platform:junit-platform-suite:1.8.2",
        "org.junit.platform:junit-platform-suite-api:1.8.2",
        "org.junit.platform:junit-platform-suite-engine:1.8.2",
        "org.junit.platform:junit-platform-testkit:1.8.2",
        "org.junit.vintage:junit-vintage-engine:5.8.2",
        "org.mockito:mockito-core:4.8.1",
    ],
    fail_if_repin_required = True,
    fetch_sources = True,
    lock_file = "//:contrib_rules_jvm_tests_install.json",
)
use_repo(
    dev_maven,
    "contrib_rules_jvm_tests",
)

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.23.6")

go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
use_repo(
    go_deps,
    "com_github_aristanetworks_goarista",
    "com_github_bazelbuild_buildtools",
    "com_github_google_btree",
    "com_github_google_go_cmp",
    "com_github_google_uuid",
    "com_github_hashicorp_golang_lru",
    "com_github_rs_zerolog",
    "com_github_sergi_go_diff",
    "com_github_stretchr_testify",
    "net_starlark_go",
    "org_golang_google_grpc",
    "org_golang_x_tools",
    "org_golang_x_tools_go_vcs",
)
